package WinterHomework.day04;

import java.util.Random;

//给定一个3乘于3的二维数组，里面的数据随机生成，分别求出两个对角线之和
public class Demo02 {
    public static void main(String[] args) {
        int[][] arr = new int[3][3];
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = random.nextInt(101);
            }
        }
        //正对角线
        int sum1 = 0;
        //反对角线
        int sum2 = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (i == j) {
                    sum1 += arr[i][j];
                }
                if (i + j == arr.length - 1) {
                    sum2 += arr[i][j];
                }
            }
        }
        System.out.println("正对角线和：" + sum1);
        System.out.println("斜对角线和：" + sum2);
    }
}
